/**
 * Created by Administrator on 2016/7/14.
 */
$(document).ready(function() {
    //首次加载
    var name = sessionStorage.searchName;
    showResult();
    //取消跳转
    $("header p").click(function(){
        history.go(-1);
    })
    //输入框搜索结果请求
    $(document).keypress(function(e) {
        // 回车键事件
        if(e.which == 13) {
            var value = $("header input").val();
            if(value == ''){
                createWindow("输入医生姓名为空，未搜索到结果");
                function createWindow(msg) {
                    var window =$("<section class='showMsg'></section>");
                    var show = "<p>"+msg+"</p>";
                    window.append(show);
                    $("body").append(window);
                    setTimeout("$('.showMsg').remove()",3000);
                }
            }else{
                name=value;
                $("")
                showResult();
            }
        }
    });


});
//定义展示搜索结果列表方法
function showResult(){
    var name = sessionStorage.searchName;
    var token = $.md5("http://dev.haotoufa.com/search@haotoufa");
    $.post("http://dev.haotoufa.com/search", {
        name: name,
        token: token
    }, function (data) {
        if (data.status == 0) {
            createWindow("查询医生信息失败");
            function createWindow(msg) {
                var window = $("<section class='showMsg'></section>");
                var show = "<p>" + msg + "</p>";
                window.append(show);
                $("body").append(window);
                setTimeout("$('.showMsg').remove()", 3000);
            }
        } else {
            if (data.data == '') {
                createWindow("没有符合您查询要求的医生");
                function createWindow(msg) {
                    var window = $("<section class='showMsg'></section>");
                    var show = "<p>" + msg + "</p>";
                    window.append(show);
                    $("body").append(window);
                    setTimeout("$('.showMsg').remove()", 3000);
                }
            } else {
                var consultList = new Vue({
                    el: '#mainPart',
                    data: {
                        items: data.data.doctor_list
                    }
                });
                $(".body").click(function(){
                    var d_id = $(this).children(".extra").children("p").text();
                    location.href="doctorInfo.html?d_id="+d_id;
                })
            }
        }
    });
}